<!DOCTYPE html>
<html lang="en">
<title>客户管理</title>
<#import "/layout/layout.html" as body/>
<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 class="pull-left">客户列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form class="form-inline" role="form">
                        	<div class="form-group">
                                <label for="customName">昵称：</label>
                                <input class="form-control" type="text" id="nickName" name="nickName" placeholder="用户昵称"/>
                            </div>
                            <div class="form-group">
                                <label for="customName">用户Id：</label>
                                <input class="form-control" type="number" id="userId" name="userId" placeholder="用户昵称"/>
                            </div>
                            <div class="form-group">
                                <label for="customName">客户手机号：</label>
                                <input class="form-control" type="text" id="mobile" name="mobile" placeholder="输入用户手机号"/>
                            </div>
                            <div class="form-group">
                                <label>客户类型：</label>
                                <select class="form-control" id="customLevel" name="customLevel">
                                    <option value="0">全部</option>
                                    <option value="1">普通用户</option>
                                    <option value="2">檬会员</option>
                                </select>
                            </div>
                            <button type="button" onclick="custom_list(0)" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                        </form>
                        <hr>
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>用户ID</th>
                                <th>微信昵称</th>
                                <th>手机号码</th>
                                <th>账户余额</th>
                                <th>用户类型</th>
                                <th>购买次数</th>
                                <th>最近门店</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="custom_list">
                            </tbody>
                        </table>
                    </div>

                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">合计：<span id="customCount">0</span>位用户</h4>
                    <div id="copot-page" class="pull-right"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 模态框 start -->
<div class="modal fade" id="blacklist" tabindex="-1" role="dialog" >
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel" >是否确将用户拉黑</h4>
      </div>
      <div class="modal-body">
				<div class="row">
					<div class="col-lg-12">
						<div class="ibox float-e-margins">
							<form class="form-inline" role="form" action="" role="form2" id="form2" method="post" accept-charset="UTF-8">
								<input type="hidden" name="blacklistuserId" id="blacklistuserId">
								<input class="form-control" name="blacklistText" id="blacklistText" type="text" style="width:350px" placeholder="拉黑理由"/>
							</form>
						</div>
					</div>
				</div>
	  </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" id="btn_blacklist">确定</button>
      </div>
    </div>
  </div>
</div>
<!-- 模态框 start -->
<script>
    $(document).ready(function () {

        custom_list(0);

        //导出excel
        //ExampleFile("用户excel");
        $("#btn_blacklist").click(function(){
        	pullBlacklist();
        });
    });

    function custom_list(currentIndex) {
        $("#custom_list").empty();
        $.ajax({
            url: "${baseUrl}/system/custom/custom_list",
            type: "POST",
            data: {
                "pageIndex": currentIndex,
                "pageSize": 20,
                "mobile":$("#mobile").val(),
                "customLevel":$("#customLevel").val(),
                "nickName":$("#nickName").val(),
                "id":$("#userId").val()
            },
            success: function (result) {
                var html = "";
                debugger;
                //分页
                new Page({
                    parent: $("#copot-page"),
                    nowPage: result.pageIndex,
                    pageSize: 20,
                    totalCount: result.custom_count,
                    setting: {
                        defaultPage: 7,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        custom_list(nowPage);
                    }
                });
                $("#mobile").val(result.mobile);
                $("#nickName").val(result.nickName);
                $("#userId").val(result.id==0?'':result.id);
                var userInfo = result.userInfo;
                $("#customCount").text(result.custom_count);
                $.each(result.custom_list, function (i, result) {
                	var dict_name = "";
                	if(result.isBlacklist == 1){
                		dict_name = result.dict_name+"(黑名单用户)";
                	}else{
                		dict_name = result.dict_name;
                	}
                    html += "<tr><td>" + result.userId + "</td>";
                    html += "<td>" + result.nickName + "</td>";
                    html += "<td>" + result.mobile + "</td>";
                    html += "<td>" + result.accountAmt + "</td>";
                    html += "<td>" + dict_name + "</td>";
                    html += "<td>" + result.buyCount + "</td>";
                    html += "<td>" + result.lastStore + "</td>";
                    html += "<td><a href='${baseUrl}/system/cashcard/to_recharge_list?userId="+result.userId+"' class='btn btn-default'><i class='fa fa-folder'></i> 充值记录</a>";
                    html += "<a href='${baseUrl}/system/cashcard/to_consume_list?userId="+result.userId+"' class='btn btn-default'><i class='fa fa-folder-open'></i> 消费记录</a>";
                    if(userInfo != null && userInfo != '' && userInfo.roleId == 2){
                    	html += "<a href='${baseUrl}/system/cashcard/to_recharge_list?userId="+result.userId+"&rechargeType=1&payStatus=1' class='btn btn-default'><i class='fa fa-usd'></i>退款</a>";
                    	if(result.isBlacklist == 0){
                    		var orderStatus = '<button type="button" class="btn btn-default btn-sm" {cancelOrder}>'
   							 +'<span class="glyphicon glyphicon-ban-circle"></span>拉黑</button>';
   							orderStatus = orderStatus.replace("{cancelOrder}","onclick=pullBlacklistModal('"+result.userId+"','"+result.nickName+"')");
                    		html += orderStatus;
                    		
                    	}
                    	
                    }
                    html += "</td></tr>";
                });
                $("#custom_list").html(html);
            }
        });
    }
    
 	// 模态框
    function pullBlacklistModal(userId,nickName){
    	$("#myModalLabel").html("是否确将"+nickName+"拉黑Id为："+userId);
    	$("#blacklistuserId").val(userId);
    	$('#blacklist').modal('show');
    }
    
 	// 拉黑名单
    function pullBlacklist(){
    	var url = "${baseUrl}/system/custom/pull_blacklist";
    	var param = getParam();
    	$('#blacklist').modal('hide');
    	Ajax(url,param,custom_list(0));
    	$("#blacklistuserId").val("");
    	$("#blacklistText").val("");
    }
 	// 获取参数
    function getParam(){
    	var param = {
        	"userId":$("#blacklistuserId").val(),
        	"remark":$("#blacklistText").val()
        }
    	return param;
    }
 	// 异步请求
    function Ajax(url,param,callBack){
    	$.ajax({
            url: url,//
            data: param,
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
            	if(data.ret == 0){
            		swal("拉黑成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                    	custom_list(0);
                    }, 1000);
            	}else{
            		swal("拉黑失败!", "请联系管理员处理", "error");
            	}
            },
            error: function () {
            	swal("拉黑失败!", "系统异常请联系管理员处理", "error");
            }
        });
    }
</script>

</@body.page>
</html>